from pyl7plot import Plot, JS

data = {
    "type": "FeatureCollection",
    "features": [
        {
            "type": "Feature",
            "id": "01",
            "properties": {
                "name": "Alabama",
                "density": 94.65
            },
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [
                            -87.359296,
                            35.00118
                        ],
                        [
                            -85.606675,
                            34.984749
                        ],
                        [
                            -85.431413,
                            34.124869
                        ],
                        [
                            -85.184951,
                            32.859696
                        ],
                        [
                            -85.069935,
                            32.580372
                        ],
                        [
                            -84.960397,
                            32.421541
                        ],
                        [
                            -85.004212,
                            32.322956
                        ],
                        [
                            -84.889196,
                            32.262709
                        ],
                        [
                            -85.058981,
                            32.13674
                        ],
                        [
                            -85.053504,
                            32.01077
                        ],
                        [
                            -85.141136,
                            31.840985
                        ],
                        [
                            -85.042551,
                            31.539753
                        ],
                        [
                            -85.113751,
                            31.27686
                        ],
                        [
                            -85.004212,
                            31.003013
                        ],
                        [
                            -85.497137,
                            30.997536
                        ],
                        [
                            -87.600282,
                            30.997536
                        ],
                        [
                            -87.633143,
                            30.86609
                        ],
                        [
                            -87.408589,
                            30.674397
                        ],
                        [
                            -87.446927,
                            30.510088
                        ],
                        [
                            -87.37025,
                            30.427934
                        ],
                        [
                            -87.518128,
                            30.280057
                        ],
                        [
                            -87.655051,
                            30.247195
                        ],
                        [
                            -87.90699,
                            30.411504
                        ],
                        [
                            -87.934375,
                            30.657966
                        ],
                        [
                            -88.011052,
                            30.685351
                        ],
                        [
                            -88.10416,
                            30.499135
                        ],
                        [
                            -88.137022,
                            30.318396
                        ],
                        [
                            -88.394438,
                            30.367688
                        ],
                        [
                            -88.471115,
                            31.895754
                        ],
                        [
                            -88.241084,
                            33.796253
                        ],
                        [
                            -88.098683,
                            34.891641
                        ],
                        [
                            -88.202745,
                            34.995703
                        ],
                        [
                            -87.359296,
                            35.00118
                        ]
                    ]
                ]
            }
        },
        {
            "type": "Feature",
            "id": "04",
            "properties": {
                "name": "Arizona",
                "density": 157.05
            },
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [
                            -109.042503,
                            37.000263
                        ],
                        [
                            -109.04798,
                            31.331629
                        ],
                        [
                            -111.074448,
                            31.331629
                        ],
                        [
                            -112.246513,
                            31.704061
                        ],
                        [
                            -114.815198,
                            32.492741
                        ],
                        [
                            -114.72209,
                            32.717295
                        ],
                        [
                            -114.524921,
                            32.755634
                        ],
                        [
                            -114.470151,
                            32.843265
                        ],
                        [
                            -114.524921,
                            33.029481
                        ],
                        [
                            -114.661844,
                            33.034958
                        ],
                        [
                            -114.727567,
                            33.40739
                        ],
                        [
                            -114.524921,
                            33.54979
                        ],
                        [
                            -114.497536,
                            33.697668
                        ],
                        [
                            -114.535874,
                            33.933176
                        ],
                        [
                            -114.415382,
                            34.108438
                        ],
                        [
                            -114.256551,
                            34.174162
                        ],
                        [
                            -114.136058,
                            34.305608
                        ],
                        [
                            -114.333228,
                            34.448009
                        ],
                        [
                            -114.470151,
                            34.710902
                        ],
                        [
                            -114.634459,
                            34.87521
                        ],
                        [
                            -114.634459,
                            35.00118
                        ],
                        [
                            -114.574213,
                            35.138103
                        ],
                        [
                            -114.596121,
                            35.324319
                        ],
                        [
                            -114.678275,
                            35.516012
                        ],
                        [
                            -114.738521,
                            36.102045
                        ],
                        [
                            -114.371566,
                            36.140383
                        ],
                        [
                            -114.251074,
                            36.01989
                        ],
                        [
                            -114.152489,
                            36.025367
                        ],
                        [
                            -114.048427,
                            36.195153
                        ],
                        [
                            -114.048427,
                            37.000263
                        ],
                        [
                            -110.499369,
                            37.00574
                        ],
                        [
                            -109.042503,
                            37.000263
                        ]
                    ]
                ]
            }
        },
        {
            "type": "Feature",
            "id": "05",
            "properties": {
                "name": "Arkansas",
                "density": 46.43
            },
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [
                            -94.473842,
                            36.501861
                        ],
                        [
                            -90.152536,
                            36.496384
                        ],
                        [
                            -90.064905,
                            36.304691
                        ],
                        [
                            -90.218259,
                            36.184199
                        ],
                        [
                            -90.377091,
                            35.997983
                        ],
                        [
                            -89.730812,
                            35.997983
                        ],
                        [
                            -89.763673,
                            35.811767
                        ],
                        [
                            -89.911551,
                            35.756997
                        ],
                        [
                            -89.944412,
                            35.603643
                        ],
                        [
                            -90.130628,
                            35.439335
                        ],
                        [
                            -90.114197,
                            35.198349
                        ],
                        [
                            -90.212782,
                            35.023087
                        ],
                        [
                            -90.311367,
                            34.995703
                        ],
                        [
                            -90.251121,
                            34.908072
                        ],
                        [
                            -90.409952,
                            34.831394
                        ],
                        [
                            -90.481152,
                            34.661609
                        ],
                        [
                            -90.585214,
                            34.617794
                        ],
                        [
                            -90.568783,
                            34.420624
                        ],
                        [
                            -90.749522,
                            34.365854
                        ],
                        [
                            -90.744046,
                            34.300131
                        ],
                        [
                            -90.952169,
                            34.135823
                        ],
                        [
                            -90.891923,
                            34.026284
                        ],
                        [
                            -91.072662,
                            33.867453
                        ],
                        [
                            -91.231493,
                            33.560744
                        ],
                        [
                            -91.056231,
                            33.429298
                        ],
                        [
                            -91.143862,
                            33.347144
                        ],
                        [
                            -91.089093,
                            33.13902
                        ],
                        [
                            -91.16577,
                            33.002096
                        ],
                        [
                            -93.608485,
                            33.018527
                        ],
                        [
                            -94.041164,
                            33.018527
                        ],
                        [
                            -94.041164,
                            33.54979
                        ],
                        [
                            -94.183564,
                            33.593606
                        ],
                        [
                            -94.380734,
                            33.544313
                        ],
                        [
                            -94.484796,
                            33.637421
                        ],
                        [
                            -94.430026,
                            35.395519
                        ],
                        [
                            -94.616242,
                            36.501861
                        ],
                        [
                            -94.473842,
                            36.501861
                        ]
                    ]
                ]
            }
        },
    ]
}
areaMap = Plot("Area")

areaMap.set_options({
    "map": {
        "type": "mapbox",
        "style": "light",
        "center": [120.19382669582967, 30.258134],
        "zoom": 3,
    },
    "autoFit": True,
    "source": {
        "data": data,
        "parser": {"type": "geojson"},
    },
    "color": {
        "field": "density",
        "value": ["rgb(65,182,196)", "rgb(29,145,192)", "rgb(34,94,168)", "rgb(12,44,132)"],
        "scale": {"type": "quantize"},
    },
    "state": {"active": True, "select":  True},
    "legend": {"position": "bottomleft"},
    "tooltip": {
        "items": ["name", "density"],
    },
})

areaMap.render("area-map.html")
